import Cookie from "js-cookie"

const uToken = "token";
const darkMode = "dark_mode";
const User = "user";

//将用户存到本地
export function setUser(user){
    window.localStorage.setItem(User,JSON.stringify(user));
}
//将用户存到本地
export function getUser(){
    return JSON.parse(window.localStorage.getItem(User));
}
//删除用户
export function removeUser(){
    window.localStorage.removeAll();
}
//获取token
export function getToken(){
    return Cookie.get(uToken);
}
//设置token的过期时间，与后端保持一致
export function setToken(token){
    return Cookie.set(uToken,token,{expires: 7});
}
//删除token
export function removeToken(){
    return Cookie.remove(uToken);
}
//删除cookie当中的所有
export function removeAll(){
    return Cookie.removeAll();
}
//白天黑夜
export function setDarkMode(mode){
    return Cookie.set(darkMode,mode,{expires: 365});
}
//获取白天黑夜
export function getDarkMode(){
    return !(undefined === Cookie.get(darkMode) || "false" === Cookie.get(darkMode));
}